package com.liuxing.doctor.intercept;

import com.liuxing.doctor.entity.Doctor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @athuer 行柳
 */
@Slf4j
public class LoginIntercepter implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("执行了拦截器");
        Doctor doctor= (Doctor) request.getSession().getAttribute("doctor");
        if(doctor!=null){
            return true;
        }
        response.sendRedirect(request.getRequestURL().substring(0,16)+":"+request.getServerPort()+"/"+"login");
        return false;
    }
}
